<?php
namespace backend\models;

use Yii;
use yii\base\Model;
use yii\base\Exception;
use common\models\Employees;

class EmployeesDataForm extends Model
{
	public $id_card;
	public $realname;
	public $sex;
	public $mobile;
	public $entry;
	public $status;

	public function formName()
    {
        return '';
    }

	public function rules()
	{
		return [
			[['id_card', 'realname', 'sex', 'mobile', 'entry', 'status'], 'safe']
		];
	}

	public function query()
	{
		$data = Employees::find()->where('id <> 0');
		if ($this->id_card) {
			$data = $data->andWhere(['id_card' => $this->id_card]);
		} 
		if ($this->realname) {
			$data = $data->andWhere(['realname' => $this->realname]);
		}
		if ($this->sex) {
			$data = $data->andWhere(['sex' => $this->sex]);
		}
		if ($this->mobile) {
			$data = $data->andWhere(['mobile' => $this->mobile]);
		}
		if ($this->entry) {
			$re = explode('-', $this->entry);
			$begin = strtotime(trim($re[0]));
			$end = strtotime(trim($re[1]));
			$data = $data->andWhere('entry >= ' . $begin)->andWhere('entry <= ' . $end);
		}
		if ($this->status) {
			$data = $data->andWhere(['status' => $this->status]);
		}

		return $data;
	}

}	